/**
 * 名称: DBHelper.java
 * 描述: 
 * 类型: JAVA
 * 最近修改时间:2013-11-27 上午11:20:09
 * @since  2013-11-27
 * @author malb
 */
package com.zhangzhi.common.sql;

import org.apache.ibatis.session.ExecutorType;
import org.apache.ibatis.session.SqlSession;
import org.apache.ibatis.session.SqlSessionFactory;

/**
 * @author malb
 * 
 */
public class DBHelper {

	private static DBHelper dbHelper = null;
	private SqlSessionFactory sqlSessionFactory;

	private DBHelper() {
		sqlSessionFactory = MyBatisUtil.getSqlSessionFactory();
	}

	/**
	 * 获得批量操作接口
	 * 
	 * @return
	 */
	public SqlSession getBatchSession() {
		return this.sqlSessionFactory.openSession(ExecutorType.BATCH, false);
	}
	
	public SqlSession getSession() {
		return this.sqlSessionFactory.openSession();
	}

	public SqlSession getSession(boolean autoCommit) {
		return this.sqlSessionFactory.openSession(autoCommit);
	}

	public static DBHelper getInstance() {
		if (dbHelper == null) {
			dbHelper = new DBHelper();
		}
		return dbHelper;
	}

}
